//
//  PromotionVC.swift
//  mySwift
//
//  Created by X-MEN on 2021/12/7.
//

import UIKit
import SSZipArchive

class PromotionVC: BaseViewController {

//暗黑模式监听哪个View切换主题 在哪个位置监听
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    super.traitCollectionDidChange(previousTraitCollection)
    guard
        #available(iOS 13.0, *),
        traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection)
        else { return }
    updateTheme()
}

private func updateTheme() {
    guard #available(iOS 12.0, *) else { return }
    
    switch traitCollection.userInterfaceStyle {
    case .light:
        APPThemeChangeManage.setTheme(index: 1)
        break
    case .dark:
        APPThemeChangeManage.setTheme(index: 3)
        break
    case .unspecified:
        break
    @unknown default:
        break
    }
}


    var startDate = "";
    var endDate = "";
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        //        self.navigationController?.navigationBar.prefersLargeTitles = true;
        //        self.navigationController?.navigationItem.largeTitleDisplayMode = .automatic;
//        AppThemeManage.setTheme(index: 3)
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
      
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
 //       暗黑模式监听
//        self.view.backgroundColor = UIColor.init { (trait) -> UIColor in
//            if trait.userInterfaceStyle == .dark {
//                print("暗黑模式")
////                        AppThemeManage.current.setTheme(index: 3)
//            } else {
//                print("其它模式")
////                        AppThemeManage.current.setTheme(index: 1)
//
//            }
//            return trait.userInterfaceStyle == .dark ? .black : .white
//        }
        
        //跟随系统语言
        navigationItem.title = NSLocalizedString("label", comment: "")
        //获取第一个首选语言
        //        let str = LaguageTools.getPreferredLanguages()
        //        print(str)
        //APP内自己设置语音 zh-Hant繁体
        //        navigationItem.title = LaguageTools.getLaguageResource("zh-Hant", forKey: "label")
        
        
        // Do any additional setup after loading the view.
        //数组中的字典
        var dictArray  =  [[String : String]]()
        dictArray.append(["name" : "zhangshan"])
        print(dictArray)
        
        
        let array : [String] = ["","88","123","456","789",]
        //带下标的循环
        for (index,value) in array.enumerated() {
            print(index,value)
        }
        
        //筛选
        let tempArray = array.filter { str in
            str == "123"
        }
        print(tempArray)
        
        let tempArray2 : [Int] = array.map { str in
            Int(str) ?? 0
        }
        print(tempArray2)
        
        let numArray = [1,20,30,0.6,15]
        
        //排序
        let tempNumArray = numArray.sorted { value1, value2 in
            value1 < value2
        }
        print(tempNumArray)
        
        
        /*--------字典操作----------*/
        
        let dict : [String : Any] = ["qq" : "11222","key" : "12"]
        var dict2 : [String : Any] = ["qq" : "999","key" : "12","key33" : "1233"]
        let dict3 : [String : Any] = ["qq" : "11222","key" : "12"]
        
        //        if dict == dict2 {
        //
        //        }
        //        if dict  {
        //            <#code#>
        //        }
        
        //判断字典是否相等
        if let dict3 = dict3 as? [AnyHashable : Any] {
            if NSDictionary(dictionary: dict).isEqual(to: NSDictionary(dictionary: dict3) as! [AnyHashable : Any]) {
                print("相等")
            } else {
                print("不相等")
                
            }
        }
        
        
        //合并
        var parameters = [String: Any]()
        for (key,value) in dict {
            parameters[key] = value;
        }
        print("parameters", parameters)
        
        //合并字典
        dict2.merge(dict) { current, new in
            new
        }
        print("dict2", dict2)
        
        let string : String = parameters["qq"] as? String ?? ""
        print(String(format: "hahhaha %@",string))
        print(String(format: "NNNNN%@ ll %.1f", arguments: ["CVarArg",999.99]))

    }
    

    
    
    @IBAction func enumEvent(_ sender: Any) {
        self.navigationController?.pushViewController(EnumViewVC.init(), animated: true)
    }
    
    
    @IBAction func blockEvent(_ sender: Any) {
        let vc = BlockWithAsyncAwaitViewController.init()
        self.navigationController?.pushViewController(vc, animated: true)
        
        
    }
    
    
    @IBAction func ocEvent(_ sender: Any) {
        self.navigationController?.pushViewController(OCViewController.init(), animated: true)
    }
    
    @IBAction func qrCodeEvent(_ sender: Any) {
        self.navigationController?.pushViewController(BBScanCusViewController.init(), animated: true)
        
    }
    
    
    @IBAction func bottomShowEvent(_ sender: Any) {
        self.navigationController?.pushViewController(BottomShowViewController.init(), animated: true)
    }
    
    
    @IBAction func gesBackEvent(_ sender: Any) {
        self.navigationController?.pushViewController(BackViewController.init(), animated: true)
    }
    
    @IBAction func rili(_ sender: Any) {
        let vc = YZXSelectDateViewController.init()
        vc.confirmTheDateBlock = {[weak self] (star,end) in
            self?.startDate = star ?? "";
            self?.endDate = end ?? "";
        }
        vc.startDate = self.startDate;
        vc.endDate = self.endDate;
        self.navigationController?.pushViewController(vc, animated: true)
        
    }
    
    
    @IBAction func chat(_ sender: Any) {
        if let vc  = WZMChatViewController.init(user: WZMChatUserModel()) {
            self.navigationController?.pushViewController(vc, animated: true)
        }
        
    }
    
    @IBAction func toModel(_ sender: Any) {
        self.navigationController?.pushViewController(ToModelViewController(), animated: true)
        
    }
    
    @IBAction func stackView(_ sender: Any) {
        self.navigationController?.pushViewController(StackViewViewController(), animated: true)
    }
    
    @IBAction func changeIcon(_ sender: Any) {
        self.navigationController?.pushViewController(ChangeIconViewController(), animated: true)
        
    }
    
    
    
    
    @IBAction func changeTheme(_ sender: Any) {
        self.navigationController?.pushViewController(ChangeThemeViewController(), animated: true)
    }
    
    
    @IBAction func unZip(_ sender: Any) {
        self.navigationController?.pushViewController(ZipViewController(), animated: true)
    }
    
}
